package com.jincp.common.dialog;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;

import com.jincp.common.R;

/**
 * Created by jzxiang on 16/4/19.
 */
public class CustomViewDialog extends BaseDialogFragment {

    private static CustomViewDialog newInstance(Builder builder) {
        CustomViewDialog dialog = new CustomViewDialog();
        Bundle bundle = getArgumentBundle(builder);
        bundle.putInt("LayoutResourceId", builder.layoutResourceId);
        dialog.setArguments(bundle);
        return dialog;
    }

    @Override
    protected void convertView(@NonNull View container, BaseDialogFragment dialogFragment) {
        if (convertViewHolder != null) {
            convertViewHolder.convertView(dialogFragment, container);
        }
    }

    @Override
    protected int getLayoutId() {
        Bundle bundle = getArguments();
        if (bundle != null) {
            return bundle.getInt("LayoutResourceId");
        }
        return R.layout.empty_view;
    }


    public static class Builder extends BaseDialogBuilder<Builder, CustomViewDialog> {

        private int layoutResourceId;

        public Builder setLayoutResourceId(int layoutResourceId) {
            this.layoutResourceId = layoutResourceId;
            return this;
        }

        public CustomViewDialog build() {
            return newInstance(this);
        }
    }


    public interface ConvertViewHolder {
        void convertView(BaseDialogFragment dialogFragment, View view);
    }

    private ConvertViewHolder convertViewHolder;

    public void setConvertViewHolder(ConvertViewHolder convertViewHolder) {
        this.convertViewHolder = convertViewHolder;
    }
}
